Add error checking in the main app