Rewrite to C and port to win32