Add check for free memory