Added debugging statements, cleaned up code