move 'activate' to end, to ensure that iTerm is brought to the front

also: refactor redundant logic; fix whitespace