implement algorithm