removing duplicate code by creating functions.