Updated code, added local statistics