working version for part3