added error handling
added update function