buttons working and js refactored