Implemented BMM algorithm