carried over some changes from the main branch