Expand tests, clean up flash code