Simplified code a bit for this PR