formatting and better error handling