Speed improvement + minor bugfix