Added exception handling and improved availability checking logic