check at begin and end