replaced all errors with function to error calls