Not cleaned up, but looks like it's working.