Fixed several bugs.