fully refactored + bugfixes + comments + performance improvements