First version which passes my tests (jc.lua - testJC function)