Separated error handling functions from main file