refactored spec code to decouple testing from implementation