fix method to check undefined