Cleanup scope creation with new create_scope factory

Makes code a little cleaner and removed heavy duplication.