first algorithm - refractor