Split into multiple modules. Added main function.