Setting up flags and search, bug fixes