Cleanup comments and add documentation and preconditions