Fix errors and deprecation warnings