Might be rewritten if I find a better way.