refactor some PyPy specific (and thus normally unused) code into a separate function
remove redundant type declaration
remove unused code
fix several error/exception handling cases throughout the code base