improve code, fix problems with first finding