Add exceptional handling to pkg.
Finally fix the bug in ISSUE #7