optimizate the code with origin functions