refactored to jCORE, no errors but untested