added cache and did some design changes.