Minor refactor thanks to Luke Sandell for pointing it out. Added more tests.