added algorithm code; not yet working