Some indentation changes - and using switches instead of "if"s.