Fixed counter formatting & 64-bit warning

- `unsigned long` should use `%lu`
- `long` should use `%ld`
- added missing `long` cast to fix potential bug on 64-bit OS (also causing compiler warning)