Closes #20 and fixes a bug in #13