some rework, code prettyfication and fixes