big cleanup, all apifunctions moved to API and refactoring