major re-work. compiles, probably not working