Refactor media capture