modularization and tidy up