Fix some bugs, introduce some new ones