Implemented search behavior and fixed flag detection.