Added more logging, fixed minor potential bug, and added a schema for ealier error detection