Nemesis: an optimised algorithm for simulating planetary systems in clusters