Refactored to just the bare minimum.