Fixed the buggy code