Added integrity checking code and updated comments
Added file opening/closing functions, updated comments, and added other misc code