Updated structure of Senthil's code to try to make origin of class variables clearer and more separate.