First stab; needs a little polish, but functional.