Fix bugs introduced by new code