Add state code into module code
move core function for module function into module.c