Safety changes
Add some Python 3 compatibility

Note that this is not anywhere close to being complete.
Support marker, end_marker, limit, and XML output