minor refactoring and improved logging
fixed bug in FormatString