Moved table queries into a separate function + removed comments