updated with a working version