Move and reorganize code