Refactor api to seperate UI and REST API