Refactored code and some new functionalities.