Improved implementation of checksum, passes all checksum unit tests