better detection, fix tests