fixed debug output
bp: nicer error msg
bp: make it work in IE

tested at least in IE 10