Refactroing & bugfixing