Refactored code to reduce extranal dependency