Made more improvements. Almost ready for merge.