fix begin-end boundaries