added checks to prevent conversion errors