Migrated code structure to idiomatic style