Initial coding done. Needs testing.