Added new codes

These codes should fix the averaging problem?