Move logic to JavaScript