Slightly simplified code