Refactor a few bits