added write-to-file support and some new features