Reorganize logic code.