Polishing code and refactoring a bit