Please review the attached patch.
(Thanks to Petyo Milotinov for his invalueable help)
-- Milen A. Radev