Started refactoring, adding more comments to help with refactoring.