Did a little refactoring and commenting.