Refactored and removed some code