memory handling improvements