more refactoring and added functionality to api