Finished backend refactoring with tests