code refactorisation and 3dimage stack decomposition added.