refactored to add automated tests