added cost tracking and animation/plotting code