shit algorithm, need to tune this thing