Reorganize code into modules