Added missing tests and manage for some error cases