working version end-end