ported FSHP code