Valik's changes from SVN