Refactor spec code