bug fixes, MSVC++ compatibility, formating