changed leaves indexing to relative indexing to prevent overflow