Improved Code Structuring. Created generic functions