Some error handling added.