David's solver