Fix bug in allocating too much local memory
Make the kernel use local memory