added a main function and solved some encoding errors