several code improvements