further optimisation (add nomask test in most expensive loop)