Added tests and refactored code while adding more documentation.