big commit (sorry), more robust checks, adding some error prevention,
adding some logs