fix possible crash with swipe gesture + code simplification