Reorganize code