final working version with search for homework