simplified code a bit