Refactored Code Structure a bit