wrote buildRequest tests and optimized code in index