Refactor module hierarchy