fixing several bugs