tightening up code, better checking