Fixed more potential bugs