updated to include a demeaning step