Cleaned up code, moved reading into separate module