added more exception handling