more compact implementation
remove some puts
remove one variable dependency