refactoring code & clean up