output changed to binary format
refactored