fixed button handling and small syntax errors