still not done and code is untested, but it is getting better