Bug fixed & rewrited functions