Finished c functions sorta