Minor bugfix and optimisation