Fixed ticket 4686 [Version 2].

See http://bugs.sugarlabs.org/ticket/4686 for more.

Also, please see #244. This patch has the suggested improvements.