DRY'ed up the JS