minor changes
added algorithm