Reorganise code in files, add tests with mocking