added garbage collecting code