Moved copied code from Kaeptn into a new c module