rewritten main engine, improved logs, added more checks

also added some comments