init algorithm