refurbished the implementation in go