refactored plus some fixes