fixed buggy code