Added error handeling and prettyprint.