add some improvements, next is a cache for weights