improve clip algorthim