Fix some bugs introduced by last commit