added support of saveing to file