Modularized the entire code