rewritted all logic