Moved level io to its own class

Fixed another bug with level saving that caused every npc to be saved as
the same npc.
Switched from for loops to while loops in level saving because they are
faster with the linked lists.