Dont fetch getSelection each time, pass it into the function