Fixed several bugs here and there.