fix XS build on Windows #1433 #1681

Hi Alex! I've been having issues as in #1433 and #1681. I've reordered some includes and it compiles fine on Windows7 both 32bit and 64bit. I hope it doesn't mess with any other builds as I don't have any Linux/MacOS to test it right now.