Refactored some repetition out of lib/spec