Make naming consistent, add comments and sanity asserts