Removed unecessery passing to app to function
Major Improvements to error handling and tests