Split error handling into its own module