Applied patch from Nerijus Baliunas <nerijus@users.sourceforge.net> to