Fix truncation errors in kernel