Made specific button handling in js more generic