Modularized a bit of code