Refactor backend API