refactored and added comments and TODO items