added json mode and tweaked pathhandler