added error handling and removed some comments