I don't feel comfortable with all this code duplication; can we go back to one function?