modularized the code