evened out corner cases for var and val functions.
fixed merge conflict