Refactoring and tested

Better error handling and further simplification of Atlas class.