Updated from patch on codeplex + minor change