Some clean code and adapting to msvse2012