Partially rolled back previous fix since some of it was unnecessary.