Needs work, but demonstrates the basic idea