Cleaned up the code#5 + Error handling