Making spec tests work and code cleanup