Fix some bugs (including #1)