Refactoring. SHADOW_ALGORITHM  switch added.