Finished code for F0. Needs testing.