refactor bilinear algorithm