Code formatting and exceptions added.