working version with changes to front-end also