Moved some logic to it's own class to reduce clutter.