checking for nil
updated error messages to more clearly show where they were generated