Main algorithm modification