Merged with Patricio's code. Weights merged.