Modularized the code with procedures