now prints debugging information to a log file. Also combined similar statements when encoding and decoding to make the code shorter