added flash and handle IndexError