Move common functions to common.c