some error handling added.