'end' finally working properly