Finished. Need to remove debug messages and refactor routines.