Merged the logic with the ui