solving element variable undefined