Fixed, optimized and generalized R functions