refactored code and spec to try out using before hook