modularized code to use in next problem