replace try/except with if/else
updated string formatting - using %r in some cases to handle the fact that counts can be either integers or floats, though the float formatting is a little ugly