Fixed premature deletion of elements; commented out a lot of debugging prints