Refactor a bit (as @rossjones suggests in #39)