Further modified the code but have not found the error

The purpose of these commits is to prepare for a possible revert.