Move the functionality out of trigger(), to make it do as little as possible. Also, use '===' instead of '=='.