All untested, but also mostly translated from c
notes
read this