Fix some trick logic and add some tests