invalid memory error fixed