added error handling
fixed indenting issue