merge upstream and other bug fixes