working versin with small bugs