Refactor a bit