private Rectangle subDivide(BST node, int depth){

		if (depth == 0){
			//leaf nodes, randomly generate rectangles in this area
			areas.add(node.area);


			//randomly determine if the room is hidden or not.
			if(MapRand.randBool(HIDDEN_ROOM_PROB) == false){
				//create room within this area by the given padding
				Rectangle room = node.area;
				for(int i = 0; i < AREA_PADDING ; i++){
					room = MapRand.innerRectangle(room);
				}

				//create the room if its in specifications, otherwise its a hidden room.
				if((room.width >= MIN_ROOM_WIDTH) && (room.height >= MIN_ROOM_HEIGHT)){
					super.addRoom(room);
					//fill each room on top of corridors
					super.fillRoom(room);
					return room;
				}
			}
			
			
			//hidden room
			Point intersect = MapRand.randPoint(MapRand.innerRectangle(node.area));
			return new Rectangle(intersect.x,intersect.y,1,1);		//returns the node area as the hidden room, this room is a single point as to connect empty rooms
		}
		else{
			Rectangle original = node.area;				//the rectangle of this partition
			Rectangle r1;
			Rectangle r2;

			boolean horizontal = MapRand.randBool((original.width < original.height) ? 0.75: 0.25);
			if (horizontal){
				//horizontal split chosen
				int fraction = (int) (original.height * ROOM_SPLIT_FACTOR);
				int upperHeight = MapRand.randInt(fraction, original.height - fraction);
				int lowerHeight = original.height - upperHeight;

				r1 = new Rectangle(original.x, original.y, original.width, upperHeight);					//top
				r2 = new Rectangle(original.x, original.y + upperHeight, original.width, lowerHeight);		//bottom
			}
			else{
				//vertical split chosen
				int fraction = (int) (original.width * ROOM_SPLIT_FACTOR);
				int leftWidth = MapRand.randInt(fraction, original.width - fraction);
				int rightWidth = original.width - leftWidth;

				r1 = new Rectangle (original.x, original.y, leftWidth, original.height);					//left
				r2 = new Rectangle (original.x + leftWidth, original.y, rightWidth, original.height);		//right
			}

			node.left = new BST(null, null, r1);
			node.right = new BST(null, null, r2);

			//Continue to subdivide.
			Rectangle roomLeft = subDivide(node.left, depth-1);
			Rectangle roomRight = subDivide(node.right, depth-1);

			//Connect each room to its sibling

			if (horizontal){
				//horizontal split chosen, r1 is top, r2 is bottom
				Rectangle top = MapRand.innerRectangle(roomLeft);
				Rectangle bottom = MapRand.innerRectangle(roomRight);

				Point start = MapRand.randRectEdge(top, RectangleSide.BOTTOM);
				Point end =  MapRand.randRectEdge(bottom, RectangleSide.TOP);
				Point mid = new Point(MapRand.randInt(r2.x, r2.x + r2.width-1), r2.y);


				super.fillCorridor(start, mid, end, MapTile.CORRIDOR_FLOOR, false);


			}
			else{
				//vertical split, r1 is left, r2 is bottom
				Rectangle left = MapRand.innerRectangle(roomLeft);
				Rectangle right = MapRand.innerRectangle(roomRight);


				Point start = MapRand.randRectEdge(left, RectangleSide.RIGHT);
				Point end =  MapRand.randRectEdge(right, RectangleSide.LEFT);
				Point mid = new Point(r2.x, MapRand.randInt(r2.y, r2.y + r2.height-1));


				super.fillCorridor(start, mid, end, MapTile.CORRIDOR_FLOOR, true);
			}

			return (MapRand.randBool() == true) ? roomLeft : roomRight;

		}

	}