Changed sanity checks and added comments