cave implementation, tests