Refactors thanks to Blair Archibald's comments!