written everything out in C