Cleaned flash and added error tests