Separate algorithm from UI