Fix #17 and some tests