not sure yet exactly how to clean this up, but this should be refactored to remove duplication