normal algorithm code