implemented mean calculation; major fixes