Completed port. fixed encoding issues.