Performance enchancments and bugfixes.