further updated code as per feedback from review using http://pareview.sh