added the bulk of it. needs tweaking.