fixing memory error