fixed some buggy code