Refactored. Half-working for binary
Half done
Half done 2