working on algorithm structure