Rewritten C app. TODO: fix signals handling.