generating b vector correctly now and changed template parameters to T