fixing several bugs.