Port to C

Quicker and more secure.

Enjoy!