Fix memleaks, minor cleanups

Change-Id: I4c27ff6bdfb3960029211b28dd229b1fd560140c
Merge pull request #14 from tribal-tec/master

Fix memleaks, minor cleanups