Note: I haven't run this code, it may not work as expected.