More refactoring. 256 colour support and more fixes.