major bug fix 2nd attempt