added fixes from main branch plus some cleanup