Refactored to add functions