Fixed some bugs found by the system tests