Altered to work with generic values instead of integers.