Wait for memory to be freed; Some fixes