BUGFIX: correct return values and clean up code
Merge pull request #7 from xini/master

BUGFIX: correct return values and clean up code