code from smik-solver