refactoring, bug with unicode and first page fixed