Use of algorithms in the STL should be promoted where possible. Also fixed up some whitespace issues.