Refactored trigger handlers code into a more coherent structure.