VS2012 warnings: more conversion warnings and a few others

These commits fix various warnings that I encountered when compiling on VS2012. Majority of these warnings are conversion warnings such as:
`warning C4242: 'argument' : conversion from 'int' to 'unsigned char', possible loss of data`