use readline instead of read()