Reduce some code duplication