code for api reduced to four lines