Added delete() where necessary.

Memory usage dropped from 980MB to 230MB.