refactored screenshot code