Added more exception checking