Refactor screen capture