DRY'd up js