Fixed code! eek! also added error handling