Replicated reported issue with sourceline
Added workaround for line numbers > 65535
Tidied up and added some comments
Namespace handling, and some handling of different output types