Fixing bugs introduced by commit cec12cd7f807b39d6d06337962d03f215da4016d