Added free memory check