Some clean up and refactoring