further work on main and shadow estimation. there is still an error to fix in shadow estimation