reconstruct determine.js and perfect logic