Refactored and removed code duplications