Got working but needs lots of cleanup.