Fixed potential bugs