Fixing some issues with #18 and rebasing all changes into one commit.