Fixes for upstream

minor cleanups which supposed not to change logic, but
make code cleaner.