rewrite code after review