crowd.php code refactor