Greatly improved performance

Also fixed bugs with locks; Performance boost at the cost of very
slight accuracy issues (hash collisions)