almost done. needs some checking