finished code after review