Replaced main with init, main_loop and terminate functions.