adding functions with parameters and some optimizations