added algorithm code; not working