Refactored and removed junk code