Refactoring a few bits