Applied fix suggested in bug 3282 and shortened code