Update for error messages
Re-organize code blocks