Merge pull request #16 from 30x/XAPID-1088

[XAPID-1088] fix resource leak, fix bugs