Could use some refactoring love here for readability.