Closes #41 and first version of #40