finishing adding code comments and some refactoring