First commit.

Full working script. Support caching.