moded into one ruby block to avoid scoping issues