Modularized the code.