better error checking and added lazy mode