refactored to avoid ajax refresh