updated internal function 'gen.S' to avoid discretisation errors.