merged working version