avoid using lists:reverse for performance issue
bug fix for searching