removed debugging statements, cleaned memory functions