various revisions to most functions. testcases 1-5 now working