Simplified code a bit