a spot of refactoring to make things look nicer and behave less hackishly