moved calculation to function
Commented code