refactored and added ability to set duration