Refactor a bit, prepare for QuickCheck