Revamped hack to be a little less hacky and work in all cases.