remove trash algorithm