katie - adding some optermization code.