cleaning up, adding tests. still more testing needed.