some changes to avoid exceptions