added error handling in register function