EG: cleaned up a lot of code