Slight refactor, not sure what I was thinking when I originally wrote this.