Working improved version