You forgot to add the HSBToLong function in that code
Also, what min and max values should hsHue, hsSat and hsL have?