Refactoring and tested.