fixing bug with function calls inside if-then-else