Refactor sample controller