Refactor and add specs