RES bug fix provided by 7oby.