Cleaned up the bracketing, indenting and removed some unused/commented code