Changed allocation of module_state structure to use malloc.