bug fixed working version