Simplifying some code and adding output for TypeErrors