Add support for windows (VC2013)

also fix some existing bugs...