add some checks to prevent error