refactored and removed unnnecessary calculations