improved error handling
code formatting