Simplified code, removed duplicate chunks