added some error checking
Removed garbage