move logic out from UI