Much hack, but it works well.