Moved picture taking inside the if statement