Increased error handling and elaborated test cases

Think the test cases are done except for opening a temporary directory
to handle checking invalid structures for the credentials file