fixed indexing problem in leave