Refactored + bugfixes