add some exception handling and remove unused parts
add more exception handling