Updted code after clean up