reorganized code to better separate mocked part from the rest of it