Better RTL detection algorithm