Made Dispose method a bit more safe.