Simplified some code before posting