Fix some bug. This is the first working implementation. Still need some workaround to enable real program to run.