refactored, simpler logic, web and buttons