maybe minor improvements in searching? also refactored a bit