Cleanup code

Cleanup whole codes, use new extension methods in CommonExtensions.cs.