Error check added