Cleaned up
Cleaned up and added error checking