adds error message and fix undefined issue