PEP8 compliance and more specific error handling