more debug and error checks