This should work, but needs cleaning up