Refactor tuptoaster.c code