Fixed buggy code