Search improved, also some other code issues.

This was really awful. And still is.