Modularized some code