Minor bugfix and performance improvement