Code cleanup & commenting. Some code refactoring.