fix encoding error, add lodash, improve debug output