added comments and started refactor