Fixed build errors in VS2013

Second attempt of #1030. All but one build error have already been fixed since.