Refactor the backend