private HashSet<String> getNextLayer(HashSet<String> currentLayer,
	    HashSet<String> dict, String end, HashSet<String> visited) {

	HashSet<String> nextLayer = new HashSet<String>();

	for (String currtStr : currentLayer) {
	    StringBuffer sb = new StringBuffer(currtStr);
	    for (int i = 0; i < sb.length(); i++) {
		char currtChar = sb.charAt(i);
		for (char ch = 'a'; ch <= 'z'; ch++) {

		    sb.setCharAt(i, ch);

		    if (end.equals(sb.toString())) {
			nextLayer.add(sb.toString());
			return nextLayer;
		    }

		    if (dict.contains(sb.toString())
			    && !visited.contains(sb.toString())) {
			nextLayer.add(sb.toString());
		    }
		}
		// reset the chat at current position
		sb.setCharAt(i, currtChar);
	    }
	}

	visited.addAll(nextLayer);
	return nextLayer;
    }