updated internal variables, added has_var guards, general cleanup