PM: Reduce code duplication between main.c and user.c