Some more code refactoring