Moved some code from handler to core. Removed unused APIcall