added joseph's new code