upgrade

Added new methods, improved function and fixed writing to output file