Refactor a bit (hopefully)