refactor javascript code so we don't do the same thing for each arrow