cleaned up code and added a more robust output data parser