Code re-organization

Split into multiple files to group related functionalities.