add array_key_exists check to getElement method