Convert to use nesting and variables