Fix for #16 including a bunch of new tests