Rewrote using maps.