Fixes open_by_location() and some misc cleanup