Refactor code

After reading:
-
http://blog.goyello.com/2013/01/07/8-most-common-mistakes-c-developers-make/

-
http://www.codingware.com/2011/02/difference-between-c-cast-syntax-and-as.html

And add some XML comment.