Some code refactoring