Moved some code from main to handlers.c.