Add new functions and reorganize code.