standardize comments and refactor