Added check to make sure the object passed is the correct type.

Also a bit of variable renaming.