added utility functions for better debug messages.
fixed CRC calculation