Fixed global variable issue

Also removed {} in one line if statements.