trying to improve weights calculation efficiency