Improve checksum helper function