Card 772 refactor code for tests to pass