Fixing various bugs.