minor cleanup, mostly related to function vs block scoping
added more tests of clause ordering