refactored ruby snippets