closes #20, also fixed a few bugs