Fix PEP8 and deprecation issues