Did some code refactoring