modularizing the code a bit