Improving pages api method