Added 'end' to calcOffset