Refactor spam conditional with nesting