DELTASPIKE-726 reverted old correct logic, fixed a minor bug and added comments