Fix bugged type check, add some logging