updated code after review