primary algorithm