updated code to be smarter and included scatter and frightened mode