source code refactoring and organizing, adding comments