Added some debug stuff, possible fix for #348 and #335