Refactor and fix click handling.
Fix table layout that was broken by last commit.