Refactoring, commenting, documentation and functionality improvements.