Refactor specs and working code