Compilation fixes for MSVC

Compilation fixes for Visual C++. Several ```using namespace std::tr1;``` declarations were causing redefinition errors with ```boost::shared_ptr```. There were also some issues with ```std::vector``` range checking in debug mode and a buffer overflow which caused heap corruption.

Tested on Visual C++ 2012 / boost 1.51.0 and gcc 4.7.2 / boost 1.48.0 (Fedora 17.)