Change bytes() to encode() to ensure Python 2 back compatability