Split cave.c up a bit