Refactor backend