Adding token authentication for mobile api calls and some refactoring