added exceptions and did some reformatting