Refactor things a bit