Extracted duplicate functionality. Formatting.
Added test.
Removed unnecessary line.
Merge pull request #482 from rackerlabs/sethbrayman

Removed code duplication.