Added better error handling and refactored Cirrus code