[IMP] Improved code as per apr's comment.