fix bug, the if branches were not properly closed