Fixes #4 and some cleanup