Add an input thread to take input from the user, and added some commenting