Changed kernel calculation to avoid inf