Update header file as well as fix some logical errors.