Add traps, small refactor and a fix