Add is_var/1 to typespecs and move guards to end of spec

Closes #1327.