Some fixes for bugs introduced by previous commits