Corrected notice and error handling to add to the messages array.