fix issue #13
fix issue #14 and #15
support both Python 2 and 3
mergin some commits from @gfxmonk to fix exit codes