Fixed bug in memory handling.