(M)almost done. todo fixed bug and improve ued.