Merge pull request #40 from ytsuboi/master

Fixed error handling and cleanup