Small optimization and bugfix.