Some logical fixes