Memory bugs fixed