Improved q1, also made it use stdin