Refactored and removed superfluous code