fix duration calculation for feature; reorganise code