bugfix for nearest neighbor search, added Casting, load/save bugfix