clean up and code refactoring