Adds unit tests and refactors block for mocking purposes