simplified some of the code