Button code refactored, may fix reported bugs.