Fixed encoding issues and various other bugs