adding debug output where it makes sense