Added xml option, cleaned up code a bit maybe