Bug fix and code minimalization