Refactor manage.php