Rewrite ugly code.