Refactor: modularized (almost) everything