Fixed algorithm; UI added.