Some error handling added