Ref #353 - Add tests. Fix detection