Refactor and fix specs