Improved logic to find traits