added a new function to remove redundant code