modified working version