updated implementation of kernel. still not complete