minor changes on algorithm