Updated code and added (limited) debugging