AutoHeathen: efactored slightly, and added unit tests