added missing curly braces on if blocks