Fix #1 and improve tests