Function handleFormat() finished.

Plus some general tidying of the code to match the original Nsx code
better.