improve memory handling