Edited Logic to integrate with UI