Check if the provided credentials is nil
Refactored the code and the tests of the AM