working version of naiave implementation