Fixing bugs 5443 and 5340