De-horrible-ify, fix, and add test