Refactored the trigger code a little bit.