Added new functionality and refactored old code.