Code Optimization - Split long method into diffrent functions

Code Optimization - Split long method into diffrent functions