Refactored code and added some functionality.