Added readline function, and greatly improved