several code fixes