Erase program bug fix and layout update

also some refactors