Major rewriting, message fixes, optimization

Many fixes, changed messages, improved features, optimized searching
algorithms...