D.R.Y.'ed the code out a bit