made the function more extandable by introducing the varialble goal