generalized a bit, trying to refamiliarize myself with the code