#488 Added logging to the api and did small refactorings