Improved some code by suggests from resharper.