Final fixes. Fully tested and ready for PR