cleaned up some code and added more logging to the service layer