Added exception checking