improving readability by using a function for frequently used code