Updated solution: Reads from STDIN