Fixed a NullReferenceException; Code clean-up