Working version but need to refine it