Made error message more descriptive. Added a few comments.