Big code cleanup and refactoring
Fixed issue regarding API authentication for logged in users