Made most of the code work. Need to stop the StackOverflow error.