Refactor internal modules (#324)