Added error checking against undefined