changed listeners and reorganized functions