Fixed various bugs.