Fix #20 and misc fixes