Final edits. Unit testing still missing.