formatting, and added more specific exception cases