working optomized verison, removed fluff