Algorithm modificated