Update handler logic and fix templates