adapted the code to use observation weights