Simplified some of the code