cleanups and free more memory