a lot of reorganizing of the code