Finished splitting up api and core functions, extern a few globals.