fixed 'end' issue