Code refactoring

Also, VKB flickering fix reverted to previous one (seems like it was the
most effective solution)