functional part is rewrited. bugs are fixed.