Refactored code to use new system