Added mean option
Bug fixes