fix issues with predefined vars and IFs

#329 and #330 in Mantis, see tests for code examples