added some logic and UI