Clean up, add some appropriate exceptions. Comments.